package com.vincent.suchao.lcld;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class GSJJ_Activity extends Activity implements OnClickListener {
	private TextView tv_tittle;
	private RelativeLayout b_gsjj;
	private RelativeLayout b_gszz;
	private Button b_back;
	private static int index = 0;
	private LinearLayout ll_circleList;
	private MySlide mySlide;
	private RelativeLayout rl_gsjj_content;
	private RelativeLayout rl_gszz_content;
	private LayoutInflater mInflater;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_gsjj);
		this.mInflater = LayoutInflater.from(this);
		init();
	}

	private void init() {
		ll_circleList = (LinearLayout) findViewById(R.id.ll_circleList);
		tv_tittle = (TextView) findViewById(R.id.tv_tittle);
		tv_tittle.setText(getString(R.string.tv_tittle_gsjs));
		b_back = (Button) findViewById(R.id.b_back);
		b_gsjj = (RelativeLayout) findViewById(R.id.b_gsjj);
		b_gszz = (RelativeLayout) findViewById(R.id.b_gszz);
		b_back.setOnClickListener(this);
		b_gsjj.setOnClickListener(this);
		b_gszz.setOnClickListener(this);
		b_gsjj.setBackgroundResource(R.drawable.gsjj_btn1_tap);
		rl_gsjj_content = (RelativeLayout) findViewById(R.id.rl_gsjj_content);
		rl_gszz_content = (RelativeLayout) findViewById(R.id.rl_gszz_content);
		int screen_width = getWindowManager().getDefaultDisplay().getWidth();
		mySlide = (MySlide) findViewById(R.id.mySlide);
		mySlide.setScreen_width(screen_width);
		mySlide.setsListener(new MySlide.SlideListener() {
			public void onComplete(int index) {
				showPageNum(index);
			}

		});

		View view = mInflater.inflate(R.layout.inflater_gszz, null);
		view.findViewById(R.id.iv_gszz).setBackgroundResource(R.drawable.gszz1);
		ImageView iv_zoom = (ImageView) view.findViewById(R.id.iv_zoom);
		iv_zoom.setOnClickListener(this);
		iv_zoom.setTag(R.id.iv_zoom, R.drawable.gszz1);
		mySlide.addView(view);
		View view2 = mInflater.inflate(R.layout.inflater_gszz, null);
		view2.findViewById(R.id.iv_gszz).setBackgroundResource(R.drawable.gszz2);
		ImageView iv_zoom2 = (ImageView) view2.findViewById(R.id.iv_zoom);
		iv_zoom2.setOnClickListener(this);
		iv_zoom2.setTag(R.id.iv_zoom, R.drawable.gszz2);
		mySlide.addView(view2);
		View view3 = mInflater.inflate(R.layout.inflater_gszz, null);
		view3.findViewById(R.id.iv_gszz).setBackgroundResource(R.drawable.gszz3);
		ImageView iv_zoom3 = (ImageView) view3.findViewById(R.id.iv_zoom);
		iv_zoom3.setOnClickListener(this);
		iv_zoom3.setTag(R.id.iv_zoom, R.drawable.gszz3);
		mySlide.addView(view3);
		View view4 = mInflater.inflate(R.layout.inflater_gszz, null);
		view4.findViewById(R.id.iv_gszz).setBackgroundResource(R.drawable.gszz4);
		ImageView iv_zoom4 = (ImageView) view4.findViewById(R.id.iv_zoom);
		iv_zoom4.setOnClickListener(this);
		iv_zoom4.setTag(R.id.iv_zoom, R.drawable.gszz4);
		mySlide.addView(view4);
		View view5 = mInflater.inflate(R.layout.inflater_gszz, null);
		view5.findViewById(R.id.iv_gszz).setBackgroundResource(R.drawable.gszz5);
		ImageView iv_zoom5 = (ImageView) view5.findViewById(R.id.iv_zoom);
		iv_zoom5.setOnClickListener(this);
		iv_zoom5.setTag(R.id.iv_zoom, R.drawable.gszz5);
		mySlide.addView(view5);
		View view6 = mInflater.inflate(R.layout.inflater_gszz, null);
		view6.findViewById(R.id.iv_gszz).setBackgroundResource(R.drawable.gszz6);
		ImageView iv_zoom6 = (ImageView) view6.findViewById(R.id.iv_zoom);
		iv_zoom6.setOnClickListener(this);
		iv_zoom6.setTag(R.id.iv_zoom, R.drawable.gszz6);
		mySlide.addView(view6);
		if (mySlide.getChildCount() > 0)
			mySlide.setToScreen(0);
	}

	public void showPageNum(int currentIndex) {
		index = currentIndex;
		ll_circleList.removeAllViews();

		for (int i = 0; i < mySlide.getChildCount(); i++) {
			ImageView iv = new ImageView(this);
			int padding = 10;
			iv.setPadding(padding, padding, padding, padding);
			int param = 31;
			LinearLayout.LayoutParams circleImage_Param = new LinearLayout.LayoutParams(param, param);

			iv.setLayoutParams(circleImage_Param);
			iv.setId(i);
			iv.setOnTouchListener(new View.OnTouchListener() {
				public boolean onTouch(View v, MotionEvent event) {
					if (event.getAction() == MotionEvent.ACTION_DOWN) {

						if (index == v.getId()) {
							return false;
						} else {
							index = v.getId();
							mySlide.setToScreen(index);
						}
					} else if (event.getAction() == MotionEvent.ACTION_UP) {

					}

					return true;
				}
			});
			if (i == index) {
				iv.setImageResource(R.drawable.circel);
			} else {
				iv.setImageResource(R.drawable.circel_null);
			}
			ll_circleList.addView(iv);
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.gsjj, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.b_gsjj:
			b_gsjj.setBackgroundResource(R.drawable.gsjj_btn1_tap);
			b_gszz.setBackgroundResource(R.drawable.selector_gsjj_btn2);
			rl_gsjj_content.setVisibility(View.VISIBLE);
			rl_gszz_content.setVisibility(View.GONE);

			break;
		case R.id.b_gszz:
			b_gsjj.setBackgroundResource(R.drawable.selector_gsjj_btn1);
			b_gszz.setBackgroundResource(R.drawable.gsjj_btn2_tap);
			rl_gsjj_content.setVisibility(View.GONE);
			rl_gszz_content.setVisibility(View.VISIBLE);
			break;
		case R.id.b_back:
			finish();
			break;
		case R.id.iv_zoom:
			int id = (Integer) v.getTag(R.id.iv_zoom);
			Intent intent = new Intent();
			intent.setClass(this, GSJJ_DetailActivity.class);
			intent.putExtra("R.id.iv_zoom", id);
			startActivity(intent);
			break;

		default:
			break;
		}

	}

}
